from bs4 import BeautifulSoup
import os
import re
import csv
import urllib2 
import random
import time


roll_call_votes=0
non_roll_call_votes=0

for file_name in os.listdir('/Users/betuldemirkaya/Desktop/Uruguay/lowerChamber/'):
	print file_name
	with open('/Users/betuldemirkaya/Desktop/Uruguay/lowerChamber/'+file_name) as f:
		myfile = f.read()
	soup=BeautifulSoup(myfile)
	soup.prettify()
	non_roll_call_votes+=len(re.findall('\(.{0,1}Se vota.{0,2}\)',soup.get_text().replace('\r','').replace('\n','')))
	roll_call_votes+=len(re.findall('\(Setomaenelsiguienteorden',soup.get_text().replace('\r','').replace('\n','').replace(' ','')))
	print roll_call_votes
	print non_roll_call_votes

upper_roll_call_votes=0
upper_non_roll_call_votes=0

for file_name in os.listdir('/Users/betuldemirkaya/Desktop/Uruguay/upperChamber/'):
	print file_name
	with open('/Users/betuldemirkaya/Desktop/Uruguay/upperChamber/'+file_name) as f:
		myfile = f.read()
	soup=BeautifulSoup(myfile)
	soup.prettify()
	upper_non_roll_call_votes+=len(re.findall('\(.{0,1}Se vota.{0,2}\)',soup.get_text().replace('\r','').replace('\n',' ')))
	upper_roll_call_votes+=len(re.findall('\(Setomaenelsiguienteorden',soup.get_text().replace('\r','').replace('\n',' ').replace(' ','')))
	print upper_roll_call_votes
	print upper_non_roll_call_votes
